package com.game.modular.game.battle.process.skillEffectHandle.impl;

import com.game.modular.game.battle.process.skillEffectHandle.base.BaseSkillEffectStrategy;
import com.game.modular.game.battle.panel.attribute.domain.PlayerHeroAttribute;
import com.game.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


@Component
@SuppressWarnings("NonAsciiCharacters")
public class BloodVolumeStrategy {
    /**
     * 32	一次性恢复兵力
     * 恢复兵力
     */
    @Slf4j
    @Component
    public static class RecoverStrategy extends BaseSkillEffectStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect skillEffect) {
            apply(skillEffect);

            return skillEffect;
        }

        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            Long battleId = pvpSkillEffect.getBattleId();
            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute sourceAttribute = heroAttributeService.get(battleId, sourcePlayerHeroId);
            PlayerHeroAttribute targetAttribute = heroAttributeService.get(battleId, targetPlayerHeroId);
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();
            String fieldName = pvpSkillEffect.getSkillEffectLayer().getName();
            Integer isMagic = pvpSkillEffect.getIsMagic();
            double value = pvpSkillEffect.getMagicInfluence()/100.0;
            double strategy = coreCombatFormulaService.getRealRecover(
                    // @NotNull long 攻击方兵力,
                    sourceAttribute.getCurrentForce(),
                    // @NotNull double 攻击方策略,
                    sourceAttribute.getMagic(),
                    // @NotNull double 增减伤,
                    sourceAttribute.obtainRecoverIncrease() - targetAttribute.obtainRecoverDecrease(),
                    // @NotNull double 攻击方上回合死亡兵力,
                    targetAttribute.getLastDead(),
                    // @NotNull double 攻击方当前回合死亡兵力,
                    targetAttribute.getThisDead(),
                    // // 战法
                    // @NotNull double 攻击方基础恢复率,
                    1,
                    // @NotNull double 攻击方恢率复增长率,
                    value,
                    // @NotNull int 是否受策略影响
                    isMagic

            );
            targetAttribute.attributeUpdate(
                    fieldName,
                    strategy,
                    0,
                    1,
                    coreSkillEffectTypeId
            );
            sourceAttribute.attributeUpdate(
                    fieldName,
                    strategy,
                    1,
                    1,
                    coreSkillEffectTypeId
            );
            heroAttributeService.saveCache(sourceAttribute);
            heroAttributeService.saveCache(targetAttribute);
        }
    }

    /**
     * 51	发动一次物理攻击
     * 发动一次物理攻击
     */
    @Slf4j
    @Component
    public static class PhysicsAttackStrategy extends BaseSkillEffectStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect skillEffects) {
            effectHandle2.tryTriggerJudgment(skillEffects);
            effectHandle2.logTriggerFailReasons(skillEffects);
            apply(skillEffects);
            return skillEffects;
        }

        /**
         * 发动一次物理伤害
         */
        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            Long battleId = pvpSkillEffect.getBattleId();
            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute sourceAttribute = heroAttributeService.get(battleId, sourcePlayerHeroId);
            PlayerHeroAttribute targetAttribute = heroAttributeService.get(battleId, targetPlayerHeroId);
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();
            String fieldName = pvpSkillEffect.getSkillEffectLayer().getName();
            double value = pvpSkillEffect.getMagicInfluence()/100.0;
            Long currentForce = sourceAttribute.getCurrentForce();
            Double att = sourceAttribute.getAtt();
            Double igPhysicalDefense = sourceAttribute.getIgPhysicalDefense();
            double physicsAttackIncrease =
                    sourceAttribute.obtainPhysicsAttackIncrease() - targetAttribute.obtainPhysicsAttackDecrease();
            Double def = targetAttribute.getDef();
            double physics = coreCombatFormulaService.getPhysics(
                    currentForce,
                    att,
                    igPhysicalDefense,
                    value,
                    physicsAttackIncrease,
                    def
            );
            targetAttribute.attributeUpdate(
                    fieldName,
                    physics,
                    0,
                    1,
                    coreSkillEffectTypeId
            );
            sourceAttribute.attributeUpdate(
                    fieldName,
                    physics,
                    1,
                    1,
                    coreSkillEffectTypeId
            );
            heroAttributeService.saveCache(sourceAttribute);
            heroAttributeService.saveCache(targetAttribute);
        }

    }

    /**
     * 52	发动一次策略攻击
     * 发动一次策略攻击
     */
    @Slf4j
    @Component
    public static class StrategyStrategy extends BaseSkillEffectStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect status) {
            apply(status);
            return status;
        }

        /**
         * 发动一次策略攻击
         */
        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            Long battleId = pvpSkillEffect.getBattleId();
            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute sourceAttribute = heroAttributeService.get(battleId, sourcePlayerHeroId);
            PlayerHeroAttribute targetAttribute = heroAttributeService.get(battleId, targetPlayerHeroId);
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();
            String fieldName = pvpSkillEffect.getSkillEffectLayer().getName();
            Integer isMagic = pvpSkillEffect.getIsMagic();
            double value = pvpSkillEffect.getMagicInfluence()/100.0;
            Long currentForce = sourceAttribute.getCurrentForce();
            Double magic = sourceAttribute.getMagic();
            double igStrategicDefense = sourceAttribute.getIgStrategicDefense() + sourceAttribute.getIgDefensiveDefense();
            double strategyAttackIncrease =
                    sourceAttribute.obtainStrategyAttackIncrease() - targetAttribute.obtainStrategyAttackDecrease();
            Double targetAttributeMagic = targetAttribute.getMagic();

            double physics = coreCombatFormulaService.getStrategy(
                    //             @NotNull @Min(1L) long 进攻方兵力,
                    currentForce,
                    //             @NotNull double 攻击方策略,
                    magic,
                    //             @NotNull double 攻击方策略穿透,
                    igStrategicDefense,
                    //             @NotNull double 攻击方战法基础伤害率,
                    1,
                    //             @NotNull double 攻击方战法伤害率成长,
                    value,
                    //             @NotNull int 是 否受策略影响,
                    isMagic,
                    //             @NotNull double 攻击方增减伤,
                    strategyAttackIncrease,
                    //             @NotNull double 防守方策略
                    targetAttributeMagic
            );
            targetAttribute.attributeUpdate(
                    fieldName,
                    physics,
                    0,
                    1,
                    coreSkillEffectTypeId
            );
            sourceAttribute.attributeUpdate(
                    fieldName,
                    physics,
                    1,
                    1,
                    coreSkillEffectTypeId
            );
            heroAttributeService.saveCache(sourceAttribute);
            heroAttributeService.saveCache(targetAttribute);
        }
    }
}
